package com.sk.bilibili.apiMapper.component.converter;

import com.sk.bilibili.apiMapper.interfaces.StringConverter;
import lombok.SneakyThrows;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 邵康
 * @date 2021/7/10 21:30
 */
public class DateConverter implements StringConverter {

    @Override
    public int order() {
        return 2222;
    }

    private SimpleDateFormat dateFormat;

    public DateConverter(String pattern) {
        dateFormat=new SimpleDateFormat(pattern);
    }

    @Override
    public boolean support(Class clazz) {
        return Date.class.equals(clazz);
    }

    @SneakyThrows
    @Override
    public Object converter(String src) {
        return dateFormat.parse(src);
    }

}
